package com.happyfamily.springboot.crowdsourcingplatform.service.sun.impl;


import com.happyfamily.springboot.crowdsourcingplatform.dao.sun.TypeDao;
import com.happyfamily.springboot.crowdsourcingplatform.model.ServerType;
import com.happyfamily.springboot.crowdsourcingplatform.service.sun.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class TypeServiceImpl implements TypeService
{
	@Autowired(required = false)
	private TypeDao typeDao;

	@Override
	public boolean checkServer(String sname)
	{
		boolean flag=false;
		int n=typeDao.checkServer(sname);
		if(n==0)
		{
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean deleteNeedType(Long sid,String sname)
	{
		boolean flag=false;
		typeDao.updateNeedType(sname);
		int n=typeDao.deleteType(sid);
		if(n>0)
		{
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean deleteServerType(Long sid)
	{
		boolean flag=false;
		typeDao.updateAlianceServerType(sid);
		typeDao.updateUserServerType(sid);
		int n=typeDao.deleteType(sid);
		if(n>0)
		{
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean addServerType(String sname)
	{
		boolean flag=false;
		int n=typeDao.addServerType(sname);
		if(n>0)
		{
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean addNeedType(String sname)
	{
		boolean flag=false;
		int n=typeDao.addNeedType(sname);
		if(n>0)
		{
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean checkNeed(String sname)
	{
		boolean flag=false;
		int n=typeDao.checkNeed(sname);
		if(n==0)
		{
			flag=true;
		}
		return flag;
	}

	@Override
	public List<ServerType> getNeedType(Integer limit, Integer end)
	{
		if(limit==null)
		{
			return typeDao.getNeedType(null,null);
		}
		else
		{
			return typeDao.getNeedType(limit,limit*(end-1));
		}
	}

	@Override
	public int getNeedSum()
	{
		return typeDao.getNeedSum();
	}

	@Override
	public List<ServerType> getOtherType(Integer limit, Integer end)
	{
		return typeDao.getOtherType(limit,limit*(end-1));
	}

	@Override
	public int getOtherSum()
	{
		return typeDao.getOtherSum();
	}

	@Override
	public boolean checkOther(String sname)
	{
		boolean flag=false;
		int n=typeDao.checkOther(sname);
		if(n==0)
		{
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean addOtherType(String sname)
	{
		boolean flag=false;
		int n=typeDao.addOtherType(sname);
		if(n>0)
		{
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean deleteOtherType(Long sid)
	{
		boolean flag=false;
		int n=typeDao.deleteType(sid);
		if(n>0)
		{
			flag=true;
		}
		return flag;
	}

	@Override
	public List<ServerType> getServerType(Integer limit, Integer end)
	{
		if(limit==null)
		{
			return typeDao.getServerType(null,null);
		}
		else
		{
			return typeDao.getServerType(limit,limit*(end-1));
		}
	}

	@Override
	public int getSererSum()
	{
		return typeDao.getSererSum();
	}
}